package org.example.smartbuy.controller;

import org.example.smartbuy.Result;
import org.example.smartbuy.entity.Orderdetails;
import org.example.smartbuy.service.IOrderdetailsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderdetails")
@Tag(name = "OrderDetails Controller", description = "Operations related to order details")
public class OrderDetailsController {

    @Autowired
    private IOrderdetailsService orderDetailsService;

    /**
     * 获取某个订单详情
     * @return List<OrderDetails>
     */
    @GetMapping("/list")
    @Operation(summary = "Get the order details records", description = "Fetch a list of all order details records",
            responses = {
                    @ApiResponse(responseCode = "200", description = "操作成功"),
                    @ApiResponse(responseCode = "400", description = "操作失败")
            })
    public Result listOrderDetails(int id) {
        return Result.success(orderDetailsService.listById(id));
    }


    /**
     * 添加订单详情
     * @param orderDetails 订单详情对象
     * @return OrderDetails
     */
    @PostMapping("/add")
    @Operation(summary = "Add a new order details record", description = "Create a new order details record",
            responses = {
                    @ApiResponse(responseCode = "200", description = "操作成功"),
                    @ApiResponse(responseCode = "400", description = "操作失败")
            })
    public Result saveOrderDetails(@RequestBody Orderdetails orderDetails) {
        return Result.success(orderDetailsService.add(orderDetails));
    }

}
